<?php
	include '../ini.php';
	include '../../libraries/xl_loai_san_pham.php';
	$dt_xl_loai_san_pham=new xl_loai_san_pham;
	
	if(empty($_GET['ma']) || !is_numeric($_GET['ma']))
	{
		$_SESSION['msg'] = "Lỗi! Mã không hộp lệ, vui lòng kiểm tra lại.";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}
	$ma=$_GET['ma'];
	$loai_san_pham=$dt_xl_loai_san_pham->xem($ma);
	if($loai_san_pham=='')
	{
		$_SESSION['msg'] = "Lỗi! Mã không hộp lệ, vui lòng kiểm tra lại.";
		$_SESSION['type_msg'] = "error";
		header('Location: '.$_SERVER['HTTP_REFERER']);
		exit;
	}	
	
	function in_ten_loai_san_pham($ds_loai_san_pham, $ma, $ky_tu, $ma_chon, $ma_an)
	{
		foreach($ds_loai_san_pham as $loai_san_pham)
		{
			if($loai_san_pham['ma_loai_cha']==$ma && $loai_san_pham['ma']!=$ma_an)
			{
				if($loai_san_pham['ma']==$ma_chon)
				{
					echo '<option selected="selected" value="'.$loai_san_pham['ma'].'">'.$ky_tu.$loai_san_pham['ten'].'</option>';
				}
				else
				{
					echo '<option value="'.$loai_san_pham['ma'].'">'.$ky_tu.$loai_san_pham['ten'].'</option>';
				}
				in_ten_loai_san_pham($ds_loai_san_pham, $loai_san_pham['ma'], $ky_tu.$ky_tu, $ma_chon, $ma_an);
			}
		}
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include'../widgets/js_css.php'?>
</head>
<body>
<div id="body-wrapper"> <!-- Wrapper for the radial gradient background -->
  
  <?php include '../widgets/sidebar.php'?>
  <div id="main-content"> <!-- Main Content Section with everything -->
  <!--noscript-->
    <!-- Page Head --> 
    <!-- End .shortcut-buttons-set -->
    
    <div class="clear"></div>
    <!-- End .clear -->
    
    <div class="content-box"><!-- Start Content Box -->
      
      <div class="content-box-header">
        <h3>Sửa loại sản phẩm</h3>
        <div class="clear"></div>
      </div>
      <!-- End .content-box-header -->
      
      <div class="content-box-content">
        <div id="tab2" class="tab-content default-tab" style="display: block;"> 
          <!-- Start Notifications --> 
          <!-- End Notifications -->
          <?php thong_bao()?>
          <form action="cap_nhat_sm.php" name="f2" method="post" onsubmit="return kiem_tra()">
            <table border="0" width="100%">
              <tbody>
              	<input type="hidden" name="ma" value="<?php echo $loai_san_pham['ma']?>"/>
                <tr class="alt-row">
                  <td>Tên Loại Bài Viết</td>
                  <td><input type="text" id="ten" name="ten" value="<?php echo $loai_san_pham['ten']?>" size="70"></td>
                </tr>
                <tr>
                  <td>Tên Loai Cha</td>
                  <td><select name="ma_loai_cha">
                      <option id="ma_loai_cha" name="ma_loai_cha" value="" style="text-align: center;">----- No Parent -----</option>
                      <?php
						$ds_loai_san_pham=$dt_xl_loai_san_pham->danh_sach_all();
                        in_ten_loai_san_pham($ds_loai_san_pham,0,'==',$loai_san_pham['ma_loai_cha'],$loai_san_pham['ma']);
                    ?>
                    </select></td>
                </tr>
                <tr class="alt-row">
                  <td>Thứ Tự Hiển Thị</td>
                  <td><input type="text" id="thu_tu_hien_thi" name="thu_tu_hien_thi" value="<?php echo $loai_san_pham['thu_tu_hien_thi']?>" size="70"></td>
                </tr>
                <tr>
                  <td>Mô tả</td>
                  <td><textarea class="text-input textarea wysiwyg" id="mo_ta" name="mo_ta"><?php echo $loai_san_pham['mo_ta']?></textarea></td>
                </tr>
                <tr>
                  <td colspan="2" style="text-align: center ! important;"><input type="submit" name="cap_nhat" value="Cặp nhật" class="button">
                    <input type="button" onclick="window.location.href='danh_sach.php'" value="Không lưu" class="button"></td>
                </tr>
              </tbody>
            </table>
          </form>
        </div>
        <!-- End #tab2 --> 
        
      </div>
      <!-- End .content-box-content --> 
      
    </div>
    <!-- End .content-box -->
    
    <div class="clear"></div>
    <div id="footer"> <small> <!-- Remove this notice or replace it with whatever you want --> 
    <!-- End #footer --> 
    
  </div>
  <!-- End #main-content --> 
</div>
</body>
</html>
